package day01;

import java.io.File;
import java.nio.file.FileStore;

public class FIleDemo02 {
    public static void printFile(String path) {
        int count = 0;
        File file = new File(path);
        if (file.exists()) {
            if (file.isFile()) {
                System.out.println(file.getAbsolutePath());
            } else if (file.isDirectory()) {
                File[] files= file.listFiles();
                if (files!=null && files.length>0) {
                    for (File f : files) {
                        printFile(f.getAbsolutePath());
                        count++;
                    }
                }
            }
        }
    }

    public static void printFileFilter(File file,String suffix) {
        if (file.exists()) {
            if (file.isDirectory()){
                File[] files = file.listFiles((f,name)->{
                    return name.endsWith(suffix) ? true:false;
                });
                for (int i=0;files!=null && i<files.length;i++) {
                    System.out.println(files[i].getAbsolutePath());
                }
                files = file.listFiles();
                for (int i=0;files!=null && i<files.length;i++) {
                    printFileFilter(files[i],suffix);
                }
            }
        }
    }
    public static void main(String[] args) {
        //遍历某个目录下的文件  C:\Users\ZFrankLin\Desktop\OD新卷

//        File file = new File("c:"+File.separator+"Users"+File.separator +"ZFrankLin"+ File.separator+
//                "Desktop"+File.separator+"OD新卷");
//        int count = printFile("c:"+File.separator+"Users"+File.separator +"ZFrankLin"+ File.separator+
//                "Desktop"+File.separator+"OD新卷");
//        System.out.println(count);
        File file = new File("D:\\dev\\tool\\资料");
        printFileFilter(file,".docx");



    }
}
